<template><div><h2 id="laravel-telescope" tabindex="-1"><a class="header-anchor" href="#laravel-telescope"><span>Laravel Telescope</span></a></h2>
<ul>
<li><a href="#introduction">简介</a></li>
<li><a href="#installation">安装</a>
<ul>
<li><a href="#local-only-installation">仅本地安装</a></li>
<li><a href="#configuration">配置</a></li>
<li><a href="#data-pruning">数据修改</a></li>
<li><a href="#dashboard-authorization">仪表盘授权</a></li>
</ul>
</li>
<li><a href="#upgrading-telescope">升级 Telescope</a></li>
<li><a href="#filtering">过滤</a>
<ul>
<li><a href="#filtering-entries">单项过滤</a></li>
<li><a href="#filtering-batches">批量过滤</a></li>
</ul>
</li>
<li><a href="#tagging">标记</a></li>
<li><a href="#available-watchers">可用的监视器</a>
<ul>
<li><a href="#batch-watcher">批量监视器</a></li>
<li><a href="#cache-watcher">缓存监视器</a></li>
<li><a href="#command-watcher">命令监视器</a></li>
<li><a href="#dump-watcher">输出监视器</a></li>
<li><a href="#event-watcher">事件监视器</a></li>
<li><a href="#exception-watcher">异常监视器</a></li>
<li><a href="#gate-watcher">Gate 监视器</a></li>
<li><a href="#http-client-watcher">HTTP Client 监视器</a></li>
<li><a href="#job-watcher">任务监视器</a></li>
<li><a href="#log-watcher">日志监视器</a></li>
<li><a href="#mail-watcher">邮件监视器</a></li>
<li><a href="#model-watcher">模型监视器</a></li>
<li><a href="#notification-watcher">消息通知监视器</a></li>
<li><a href="#query-watcher">数据查询监视器</a></li>
<li><a href="#redis-watcher">Redis 监视器</a></li>
<li><a href="#request-watcher">请求监视器</a></li>
<li><a href="#schedule-watcher">定时任务监视器</a></li>
<li><a href="#view-watcher">视图监视器</a></li>
</ul>
</li>
<li><a href="#displaying-user-avatars">显示用户头像</a></li>
</ul>
<h2 id="简介" tabindex="-1"><a class="header-anchor" href="#简介"><span>简介</span></a></h2>
<p><a href="https://github.com/laravel/telescope" target="_blank" rel="noopener noreferrer">Laravel Telescope</a> 是 Laravel 本地开发环境的绝佳伴侣。Telescope 可以洞察你的应用程序的请求、异常、日志条目、数据库查询、排队的作业、邮件、消息通知、缓存操作、定时计划任务、变量打印等。</p>
<p><img src="https://laravel.com/img/docs/telescope-example.png" alt="telescope-example.png"></p>
<h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<p>你可以使用 Composer 将 Telescope 安装到 Laravel 项目中：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> require laravel/telescope</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>安装 Telescope 后，你应使用 <code v-pre>telescope:install</code> 命令来发布其公共资源，然后运行 <code v-pre>migrate</code> 命令执行数据库变更来创建和保存 Telescope 需要的数据：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan telescope:install</span>
<span class="line"></span>
<span class="line">php artisan migrate</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="自定义迁移" tabindex="-1"><a class="header-anchor" href="#自定义迁移"><span>自定义迁移</span></a></h4>
<p>如果不打算使用 Telescope 的默认迁移，则应在应用程序的 <code v-pre>App\Providers\AppServiceProvider</code> 类的 <code v-pre>register</code> 方法中调用 <code v-pre>Telescope::ignoreMigrations</code> 方法。你可以使用以下命令导出默认迁移：<code v-pre>php artisan vendor:publish --tag=telescope-migrations</code></p>
<h3 id="仅本地安装" tabindex="-1"><a class="header-anchor" href="#仅本地安装"><span>仅本地安装</span></a></h3>
<p>如果你仅打算使用 Telescope 来帮助你的本地开发，你可以使用 <code v-pre>--dev</code> 标记安装 Telescope：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> require laravel/telescope <span class="token parameter variable">--dev</span></span>
<span class="line"></span>
<span class="line">php artisan telescope:install</span>
<span class="line"></span>
<span class="line">php artisan migrate</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>运行 <code v-pre>telescope:install</code> 后，应该从应用程序的 <code v-pre>config/app.php</code> 配置文件中删除 <code v-pre>TelescopeServiceProvider</code> 服务提供者注册。手动在 <code v-pre>App\Providers\AppServiceProvider</code> 类的 <code v-pre>register</code> 方法中注册 telescope 的服务提供者来替代。在注册提供者之前，我们会确保当前环境是 <code v-pre>local</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务。</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">environment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'local'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">register</span><span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified static-context"><span class="token punctuation">\</span>Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>TelescopeServiceProvider</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">register</span><span class="token punctuation">(</span><span class="token class-name static-context">TelescopeServiceProvider</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>最后，你还应该将以下内容添加到你的 <code v-pre>composer.json</code> 文件中来防止 Telescope 扩展包被 <a href="https://learnku.com/docs/laravel/10.x/packages#package-discovery" target="_blank" rel="noopener noreferrer">自动发现</a>：</p>
<div class="language-json line-numbers-mode" data-highlighter="prismjs" data-ext="json" data-title="json"><pre v-pre class="language-json"><code><span class="line"><span class="token property">"extra"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token property">"laravel"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token property">"dont-discover"</span><span class="token operator">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string">"laravel/telescope"</span></span>
<span class="line">        <span class="token punctuation">]</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="配置" tabindex="-1"><a class="header-anchor" href="#配置"><span>配置</span></a></h3>
<p>发布 Telescope 的资源文件后，其主要配置文件将位于 <code v-pre>config/telescope.php</code>。此配置文件允许你配置监听 <a href="#available-watchers">观察者选项</a>，每个配置选项都包含其用途说明，因此请务必彻底浏览此文件。</p>
<p>如果需要，你可以使用 <code v-pre>enabled</code> 配置选项完全禁用 Telescope 的数据收集：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_ENABLED'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="数据修改" tabindex="-1"><a class="header-anchor" href="#数据修改"><span>数据修改</span></a></h3>
<p>有了数据修改， <code v-pre>telescope_entries</code> 表可以非常快速地累积记录。 为了缓解这个问题，你应该使用 <a href="https://learnku.com/docs/laravel/10.x/scheduling" target="_blank" rel="noopener noreferrer">调度</a> 每天运行 <code v-pre>telescope:prune</code> 命令：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$schedule</span><span class="token operator">-></span><span class="token function">command</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'telescope:prune'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">daily</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>默认情况下，将获取超过 24 小时的所有数据。在调用命令时可以使用 <code v-pre>hours</code> 选项来确定保留 <code v-pre>Telescope</code> 数据的时间。例如，以下命令将删除 48 小时前创建的所有记录：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$schedule</span><span class="token operator">-></span><span class="token function">command</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'telescope:prune --hours=48'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">daily</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="仪表板授权" tabindex="-1"><a class="header-anchor" href="#仪表板授权"><span>仪表板授权</span></a></h3>
<p>访问 <code v-pre>/telescope</code> 即可显示仪表盘。默认情况下，你只能在 <code v-pre>local</code> 环境中访问此仪表板。 在 <code v-pre>app/Providers/TelescopeServiceProvider.php</code> 文件中，有一个 <a href="https://learnku.com/docs/laravel/10.x/authorization#gates" target="_blank" rel="noopener noreferrer">gate 授权</a> 。此授权能控制在 <strong>非本地</strong> 环境中对 Telescope 的访问。你可以根据需要随意修改此权限以限制对 Telescope 安装和访问：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>User</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册 Telescope gate。</span>
<span class="line"> *</span>
<span class="line"> * 该 gate 确定谁可以在非本地环境中访问 Telescope</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function-definition function">gate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token class-name static-context">Gate</span><span class="token operator">::</span><span class="token function">define</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'viewTelescope'</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">User</span> <span class="token variable">$user</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token function">in_array</span><span class="token punctuation">(</span><span class="token variable">$user</span><span class="token operator">-></span><span class="token property">email</span><span class="token punctuation">,</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'taylor@laravel.com'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>注意：你应该确保在生产环境中将 <code v-pre>APP_ENV</code> 环境变量更改为 <code v-pre>Production</code>。 否则，你的 Telescope 调试工具将公开可用。</p>
</blockquote>
<h2 id="更新-telescope" tabindex="-1"><a class="header-anchor" href="#更新-telescope"><span>更新 Telescope</span></a></h2>
<p>升级到 Telescope 的新主要版本时，务必仔细阅读 <a href="https://github.com/laravel/telescope/blob/master/UPGRADE.md" target="_blank" rel="noopener noreferrer">升级指南</a>.</p>
<p>此外，升级到任何新的 Telescope 版本时，你都应该重建 Telescope 实例：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan telescope:publish</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>为了使实例保持最新状态并避免将来的更新中出现问题，可以在应用程序的 <code v-pre>composer.json</code> 文件中的 <code v-pre>post-update-cmd</code> 脚本添加 <code v-pre>telescope:publish</code> 命令：</p>
<div class="language-json line-numbers-mode" data-highlighter="prismjs" data-ext="json" data-title="json"><pre v-pre class="language-json"><code><span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token property">"post-update-cmd"</span><span class="token operator">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string">"@php artisan vendor:publish --tag=laravel-assets --ansi --force"</span></span>
<span class="line">        <span class="token punctuation">]</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="过滤" tabindex="-1"><a class="header-anchor" href="#过滤"><span>过滤</span></a></h2>
<h3 id="单项过滤" tabindex="-1"><a class="header-anchor" href="#单项过滤"><span>单项过滤</span></a></h3>
<p>你可以通过在 <code v-pre>App\Providers\TelescopeServiceProvider</code> 类中定义的 <code v-pre>filter</code> 闭包来过滤 Telescope 记录的数据。 默认情况下，此回调会记录 <code v-pre>local</code> 环境中的所有数据以及异常、失败任务、计划任务和带有受监控标记的数据：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>IncomingEntry</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">environment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'local'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isReportableException</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isFailedJob</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isScheduledTask</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isSlowQuery</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">            <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">hasMonitoredTag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="批量过滤" tabindex="-1"><a class="header-anchor" href="#批量过滤"><span>批量过滤</span></a></h3>
<p><code v-pre>filter</code> 闭包过滤单个条目的数据， 你也可以使用 <code v-pre>filterBatch</code> 方法注册一个闭包，该闭包过滤给定请求或控制台命令的所有数据。如果闭包返回 <code v-pre>true</code>，则所有数据都由 Telescope 记录：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Collection</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>IncomingEntry</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> *  注册应用服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">filterBatch</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">Collection</span> <span class="token variable">$entries</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">app</span><span class="token operator">-></span><span class="token function">environment</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'local'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entries</span><span class="token operator">-></span><span class="token function">contains</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isReportableException</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isFailedJob</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isScheduledTask</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">isSlowQuery</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span></span>
<span class="line">                <span class="token variable">$entry</span><span class="token operator">-></span><span class="token function">hasMonitoredTag</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">            <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="标签" tabindex="-1"><a class="header-anchor" href="#标签"><span>标签</span></a></h2>
<p>Telescope 允许你通过 「tag」 搜索条目。通常，标签是 Eloquent 模型的类名或经过身份验证的用户 ID， 这些标签会自动添加到条目中。有时，你可能希望将自己的自定义标签附加到条目中。 你可以使用 <code v-pre>Telescope::tag</code> 方法。 <code v-pre>tag</code> 方法接受一个闭包，该闭包应返回一个标签数组。返回的标签将与 Telescope 自动附加到条目的所有标签合并。你应该在 <code v-pre>App\Providers\TelescopeServiceProvider</code> 类中的 <code v-pre>register</code> 方法调用 <code v-pre>tag</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>IncomingEntry</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">hideSensitiveRequestDetails</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">tag</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">IncomingEntry</span> <span class="token variable">$entry</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$entry</span><span class="token operator">-></span><span class="token property">type</span> <span class="token operator">===</span> <span class="token string single-quoted-string">'request'</span></span>
<span class="line">                    <span class="token operator">?</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'status:'</span><span class="token operator">.</span><span class="token variable">$entry</span><span class="token operator">-></span><span class="token property">content</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'response_status'</span><span class="token punctuation">]</span><span class="token punctuation">]</span></span>
<span class="line">                    <span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"> <span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="可用的观察者" tabindex="-1"><a class="header-anchor" href="#可用的观察者"><span>可用的观察者</span></a></h2>
<p>Telescope 「观察者」 在执行请求或控制台命令时收集应用数据。你可以在 <code v-pre>config/telescope.php</code> 配置文件中自定义启用的观察者列表：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CacheWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CommandWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>一些监视器还允许你提供额外的自定义选项：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>QueryWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_QUERY_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'slow'</span> <span class="token operator">=></span> <span class="token number">100</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="批量监视器" tabindex="-1"><a class="header-anchor" href="#批量监视器"><span>批量监视器</span></a></h3>
<p>批量监视器记录队列 <a href="https://learnku.com/docs/laravel/10.x/queues#job-batching" target="_blank" rel="noopener noreferrer">批量任务</a> 的信息，包括任务和连接信息。</p>
<h3 id="缓存监视器" tabindex="-1"><a class="header-anchor" href="#缓存监视器"><span>缓存监视器</span></a></h3>
<p>当缓存键被命中、未命中、更新和删除时，缓存监视器会记录数据。</p>
<h3 id="命令监视器" tabindex="-1"><a class="header-anchor" href="#命令监视器"><span>命令监视器</span></a></h3>
<p>只要执行 Artisan 命令，命令监视器就会记录参数、选项、退出码和输出。如果你想排除监视器记录的某些命令，你可以在 <code v-pre>config/telescope.php</code> 文件的 <code v-pre>ignore</code> 选项中指定命令：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>CommandWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_COMMAND_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'ignore'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'key:generate'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="输出监视器" tabindex="-1"><a class="header-anchor" href="#输出监视器"><span>输出监视器</span></a></h3>
<p>输出监视器在 Telescope 中记录并显示你的变量输出。使用 Laravel 时，可以使用全局 <code v-pre>dump</code> 函数输出变量。必须在浏览器中打开数据监视器选项卡，才能进行输出变量，否则监视器将忽略此次输出。</p>
<h3 id="事件监视器" tabindex="-1"><a class="header-anchor" href="#事件监视器"><span>事件监视器</span></a></h3>
<p>事件监视器记录应用分发的所有 <a href="https://learnku.com/docs/laravel/10.x/events" target="_blank" rel="noopener noreferrer">事件</a> 的有效负载、监听器和广播数据。事件监视器忽略了 Laravel 框架的内部事件。</p>
<h3 id="异常监视器" tabindex="-1"><a class="header-anchor" href="#异常监视器"><span>异常监视器</span></a></h3>
<p>异常监视器记录应用抛出的任何可报告异常的数据和堆栈跟踪。</p>
<h3 id="gate-拦截-监视器" tabindex="-1"><a class="header-anchor" href="#gate-拦截-监视器"><span>Gate（拦截）监视器</span></a></h3>
<p>Gate 监视器记录你的应用的 <a href="https://learnku.com/docs/laravel/10.x/authorization" target="_blank" rel="noopener noreferrer">gate 和策略</a> 检查的数据和结果。如果你希望将某些属性排除在监视器的记录之外，你可 <code v-pre>config/telescope.php</code> 文件的 <code v-pre>ignore_abilities</code> 选项中指定它们：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>GateWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_GATE_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'ignore_abilities'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'viewNova'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="http-客户端监视器" tabindex="-1"><a class="header-anchor" href="#http-客户端监视器"><span>HTTP 客户端监视器</span></a></h3>
<p>HTTP 客户端监视器记录你的应用程序发出的传出 <a href="https://learnku.com/docs/laravel/10.x/http-client" target="_blank" rel="noopener noreferrer">HTTP 客户端请求</a>。</p>
<h3 id="任务监视器" tabindex="-1"><a class="header-anchor" href="#任务监视器"><span>任务监视器</span></a></h3>
<p>任务监视器记录应用程序分发的任何 <a href="https://learnku.com/docs/laravel/10.x/queues" target="_blank" rel="noopener noreferrer">任务</a> 的数据和状态。</p>
<h3 id="日志监视器" tabindex="-1"><a class="header-anchor" href="#日志监视器"><span>日志监视器</span></a></h3>
<p>日志监视器记录应用程序写入的任何日志的 <a href="https://learnku.com/docs/laravel/10.x/logging" target="_blank" rel="noopener noreferrer">日志数据</a>。</p>
<p>默认情况下，Telescope 将只记录 [错误] 级别及以上的日志。但是，你可以修改应用程序的 <code v-pre>config/tescope.php</code> 配置文件中的 <code v-pre>level</code> 选项来修改此行为：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>LogWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_LOG_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'level'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'debug'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="邮件监视器" tabindex="-1"><a class="header-anchor" href="#邮件监视器"><span>邮件监视器</span></a></h3>
<p>邮件监视器允许你查看应用发送的 <a href="https://learnku.com/docs/laravel/10.x/mail" target="_blank" rel="noopener noreferrer">邮件</a> 及其相关数据的浏览器内预览。你也可以将该电子邮件下载为 <code v-pre>.eml</code> 文件。</p>
<h3 id="模型监视器" tabindex="-1"><a class="header-anchor" href="#模型监视器"><span>模型监视器</span></a></h3>
<p>每当调度 Eloquent 的 <a href="https://learnku.com/docs/laravel/10.x/eloquent#events" target="_blank" rel="noopener noreferrer">模型事件</a> 时，模型监视器就会记录模型更改。你可以通过监视器的 <code v-pre>events</code> 选项指定应记录哪些模型事件：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>ModelWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_MODEL_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'events'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'eloquent.created*'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'eloquent.updated*'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你想记录在给定请求期间融合的模型数量，请启用 <code v-pre>hydrations</code> 选项：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>ModelWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_MODEL_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'events'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'eloquent.created*'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'eloquent.updated*'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'hydrations'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="消息通知监视器" tabindex="-1"><a class="header-anchor" href="#消息通知监视器"><span>消息通知监视器</span></a></h3>
<p>消息通知监听器记录你的应用程序发送的所有 <a href="https://learnku.com/docs/laravel/10.x/notifications" target="_blank" rel="noopener noreferrer">消息通知</a> 。如果通知触发了电子邮件并且你启用了邮件监听器，则电子邮件也可以在邮件监视器屏幕上进行预览。</p>
<h3 id="数据查询监视器" tabindex="-1"><a class="header-anchor" href="#数据查询监视器"><span>数据查询监视器</span></a></h3>
<p>数据查询监视器记录应用程序执行的所有查询的原始 SQL、绑定和执行时间。监视器还将任何慢于 100 毫秒的查询标记为 <code v-pre>slow</code>。你可以使用监视器的 <code v-pre>slow</code> 选项自定义慢查询阈值：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>QueryWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_QUERY_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'slow'</span> <span class="token operator">=></span> <span class="token number">50</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="redis-监视器" tabindex="-1"><a class="header-anchor" href="#redis-监视器"><span>Redis 监视器</span></a></h3>
<p>Redis 监视器记录你的应用程序执行的所有 <a href="https://learnku.com/docs/laravel/10.x/redis" target="_blank" rel="noopener noreferrer">Redis</a> 命令。如果你使用 Redis 进行缓存，Redis 监视器也会记录缓存命令。</p>
<h3 id="请求监视器" tabindex="-1"><a class="header-anchor" href="#请求监视器"><span>请求监视器</span></a></h3>
<p>请求监视器记录与应用程序处理的任何请求相关联的请求、请求头、会话和响应数据。你可以通过 <code v-pre>size_limit</code>（以 KB 为单位）选项限制记录的响应数据：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'watchers'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token class-name class-name-fully-qualified static-context">Watchers<span class="token punctuation">\</span>RequestWatcher</span><span class="token operator">::</span><span class="token keyword">class</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'enabled'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_REQUEST_WATCHER'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'size_limit'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'TELESCOPE_RESPONSE_SIZE_LIMIT'</span><span class="token punctuation">,</span> <span class="token number">64</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="定时任务监视器" tabindex="-1"><a class="header-anchor" href="#定时任务监视器"><span>定时任务监视器</span></a></h3>
<p>定时任务监视器记录应用程序运行的任何 <a href="https://learnku.com/docs/laravel/10.x/scheduling" target="_blank" rel="noopener noreferrer">计划任务</a> 的命令和输出。</p>
<h3 id="视图监视器" tabindex="-1"><a class="header-anchor" href="#视图监视器"><span>视图监视器</span></a></h3>
<p>视图监视器记录渲染视图时使用的 <a href="https://learnku.com/docs/laravel/10.x/views" target="_blank" rel="noopener noreferrer">视图</a> 名称、路径、数据和「composer」组件。</p>
<h2 id="显示用户头像" tabindex="-1"><a class="header-anchor" href="#显示用户头像"><span>显示用户头像</span></a></h2>
<p>Telescope 仪表盘显示保存给定条目时会有登录用户的用户头像。 默认情况下，Telescope 将使用 Gravatar Web 服务检索头像。 但是，你可以通过在 <code v-pre>App\Providers\TelescopeServiceProvider</code> 类中注册一个回调来自定义头像 URL。 回调将收到用户的 ID 和电子邮件地址，并应返回用户的头像 URL：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>User</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Laravel<span class="token punctuation">\</span>Telescope<span class="token punctuation">\</span>Telescope</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 注册应用服务</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">register</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line"></span>
<span class="line">    <span class="token class-name static-context">Telescope</span><span class="token operator">::</span><span class="token function">avatar</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$id</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$email</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token string single-quoted-string">'/avatars/'</span><span class="token operator">.</span><span class="token class-name static-context">User</span><span class="token operator">::</span><span class="token function">find</span><span class="token punctuation">(</span><span class="token variable">$id</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token property">avatar_path</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/10.x/telescope/14917" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/10.x/te...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/10.x/telescope/14917" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/10.x/te...</a></p>
</blockquote>
</div></template>


